package com.gking.centerSystem.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gking.centerSystem.AOP.annotationUtil.desensitizeData.DesensitizeData;
import com.gking.centerSystem.AOP.annotationUtil.desensitizeData.SensitizedTypeEnum;
import com.gking.centerSystem.common.Result;
import com.gking.centerSystem.entity.SystemInfo;
import com.gking.centerSystem.service.SystemInfo.SystemInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;


@Slf4j
@RestController
@RequestMapping("/systemInfo")
public class SystemInfoController {

    @Resource
    private SystemInfoService systemInfoService;


    /**
     * 分页获取系统信息列表
     *
     * @param size       分页大小
     * @param page       分页页码
     * @param systemCode 系统编码
     * @return s
     */
    @DesensitizeData({
            @DesensitizeData.Field(field = "systemIP", type = SensitizedTypeEnum.IP),
    })
    @RequiresPermissions("CS:manager:get:systemInfo")
    @GetMapping("/systemInfoList")
    public Result<Page> getSystemInfoList(@RequestParam Integer size, @RequestParam Integer page,
                                          @RequestParam String systemCode) {
        return systemInfoService.getSystemInfoList(page, size, systemCode);
    }


    /**
     * 创建系统信息或者修改系统信息
     *
     * @param systemInfo 系统信息
     * @return s
     */
    @DesensitizeData(needVerify = true)
    @RequiresPermissions("CS:manager:set:systemInfo")
    @PostMapping("/setSystemInfo")
    public Result<String> setSystemInfo(@RequestBody SystemInfo systemInfo) {

        String systemInfoId = systemInfo.getId();
        String systemCode = systemInfo.getSystemCode();
        String systemIP = systemInfo.getSystemIP();
        String remark = systemInfo.getRemark();

        return systemInfoService.setSystemInfo(systemInfoId, systemCode, systemIP, remark);
    }


    /**
     * 批量删除系统信息
     *
     * @param systemInfoIdList 系统信息id列表
     * @return s
     */
    @DesensitizeData(needVerify = true)
    @RequiresPermissions("CS:manager:set:systemInfo")
    @PostMapping("/deleteSystemInfo")
    public Result<String> deleteSystemInfo(@RequestBody List<String> systemInfoIdList) {
        return systemInfoService.deleteSystemInfo(systemInfoIdList);
    }


    /**
     * 批量更新系统信息状态
     *
     * @param systemInfoIdList 系统信息 id 列表
     * @param status           状态 0启用，1禁用
     * @return s
     */
    @DesensitizeData(needVerify = true)
    @RequiresPermissions("CS:manager:set:systemInfo")
    @PostMapping("/updateSystemInfoStatus")
    public Result<String> updateSystemInfoStatus(@RequestBody List<String> systemInfoIdList,
                                                 @RequestParam Integer status) {
        return systemInfoService.updateSystemInfoStatus(systemInfoIdList, status);
    }

}
